🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / data / src / commonMain / kotlin / org / meshtastic / core / data / manager / GeofenceCrossingStore.kt
Displaying Raw • Download
core/data/src/commonMain/kotlin/org/meshtastic/core/data/manager/GeofenceCrossingStore.kt 2d20cd8a4708e2ef66e98d5259f3a97ec93f240a (2d20cd8a) Text, 2.33 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.data.manager
Tff7b72import T7ee787kotlinx.coroutines.sync.Mutex
Tff7b72import T7ee787kotlinx.coroutines.sync.withLock
Tff7b72import T7ee787org.koin.core.annotation.Single
T8b949e/** The transition observed when a node's inside/outside state for a geofence is updated. */
Tff7b72enum Tff7b72class T56d364GeofenceTransition Tb4b4b4{
T8b949e/** First time this (waypoint, node) pair was seen — establishes a baseline, never notifies. */
Te6edf3BASELINETb4b4b4,
Te6edf3ENTEREDTb4b4b4,
Te6edf3EXITEDTb4b4b4,
T8b949e/** Same side as last time — no notification. */
Te6edf3UNCHANGEDTb4b4b4,
Tb4b4b4}
T8b949e/**
* In-memory inside/outside state per `(waypointId, nodeNum)`. NOT persisted: a relaunch re-baselines, which is exactly
* what prevents spurious alerts at startup. Mutated from the service scope as positions arrive, so guarded by a
* [Mutex].
*/
Tf0883e@Single
Tff7b72class T56d364GeofenceCrossingStore Tb4b4b4{
Tff7b72private Tff7b72val Te6edf3mutex Tff7b72= Te6edf3MutexTb4b4b4(Tb4b4b4)
Tff7b72private Tff7b72val Te6edf3inside Tff7b72= Te6edf3mutableMapOfTff7b72<Te6edf3PairTff7b72<Tffa657IntTb4b4b4, Tffa657IntTff7b72>Tb4b4b4, Tffa657BooleanTff7b72>Tb4b4b4(Tb4b4b4)
T8b949e/** Record [isInside] for ([waypointId], [nodeNum]) and report the transition versus the prior state. */
Tff7b72suspend Tff7b72fun Td2a8ffupdateTb4b4b4(Te6edf3waypointIdTb4b4b4: Tffa657IntTb4b4b4, Te6edf3nodeNumTb4b4b4: Tffa657IntTb4b4b4, Te6edf3isInsideTb4b4b4: Tffa657BooleanTb4b4b4)Tb4b4b4: Te6edf3GeofenceTransition Tff7b72= Te6edf3mutexTb4b4b4.Te6edf3withLock Tb4b4b4{
Tff7b72val Te6edf3was Tff7b72= Te6edf3insideTb4b4b4.Te6edf3putTb4b4b4(Te6edf3waypointId Te6edf3to Te6edf3nodeNumTb4b4b4, Te6edf3isInsideTb4b4b4)
Tff7b72when Tb4b4b4{
Te6edf3was Tff7b72=Tff7b72= Tff7b72null Tff7b72-Tff7b72> Te6edf3GeofenceTransitionTb4b4b4.Te6edf3BASELINE
Te6edf3was Tff7b72=Tff7b72= Te6edf3isInside Tff7b72-Tff7b72> Te6edf3GeofenceTransitionTb4b4b4.Te6edf3UNCHANGED
Te6edf3isInside Tff7b72-Tff7b72> Te6edf3GeofenceTransitionTb4b4b4.Te6edf3ENTERED
Tff7b72else Tff7b72-Tff7b72> Te6edf3GeofenceTransitionTb4b4b4.Te6edf3EXITED
Tb4b4b4}
Tb4b4b4}
T8b949e/** Drop crossing state for waypoints no longer active, bounding memory growth. */
Tff7b72suspend Tff7b72fun Td2a8ffretainOnlyTb4b4b4(Te6edf3waypointIdsTb4b4b4: Te6edf3SetTff7b72<Tffa657IntTff7b72>Tb4b4b4)Tb4b4b4: Tffa657Unit Tff7b72=
Te6edf3mutexTb4b4b4.Te6edf3withLock Tb4b4b4{ Te6edf3insideTb4b4b4.Te6edf3keysTb4b4b4.Te6edf3retainAll Tb4b4b4{ Tffa657itTb4b4b4.Te6edf3first Tff7b72in Te6edf3waypointIds Tb4b4b4} Tb4b4b4}
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.07s